package com.hdax.dm.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.dto.PriceDto;
import com.hdax.dm.entity.scheduler.DmSchedulerSeatPrice;
import com.hdax.dm.mappers.SchedulerSeatPriceMapper;
import com.hdax.dm.mapstrucs.PriceDtoMapper;
import com.hdax.dm.service.SchedulerSeatPriceService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SchedulerSeatPriceSImpl extends ServiceImpl<SchedulerSeatPriceMapper,DmSchedulerSeatPrice> implements SchedulerSeatPriceService {


    @Autowired
    private PriceDtoMapper priceDaoMapper;

    @Override
    public CommonResponse<List<PriceDto>> getPrice(Integer scheduleId) {
        QueryWrapper<DmSchedulerSeatPrice> wrapper=new QueryWrapper<>();
        wrapper.eq("scheduleId",scheduleId);
        List<DmSchedulerSeatPrice> prices= list(wrapper);
        List<PriceDto> priceDto= priceDaoMapper.toTargets(prices);
        for (int i = 0; i < prices.size(); i++) {
            if(prices.get(i).getSeatNum()>0){
                priceDto.get(i).setIsHaveSeat(1L);
            }
        }
        return ResponseUtil.returnSuccess(priceDto);
    }
}
